<template>
    <div class="header-vue">
        <div class="header-img">
            <img @click="goHome"  src="https://qushen-file.oss-cn-beijing.aliyuncs.com/outsourcing-2023/zhi-hui/admin/jiahui_logo11.png"
                alt="">
        </div>
        <div>

            <el-button @click="logoutFn">
                退出登录
            </el-button>
            <!-- <el-dropdown>
                <span class="avatar-dropdown">
                    <el-avatar class="user-avatar" :draggable="false" shape="square" :size="30" :src="active" />
                    <div class="username">
                        <span class="hidden-xs-only">{{ username }}</span>
                        <vab-icon class="vab-dropdown" :class="{ 'vab-dropdown-active': active }"
                            icon="arrow-down-s-line" />
                    </div>
                </span>
                <template #dropdown>
                    <el-dropdown-menu style="padding: 0">
                        <div class="" style="width: 240px; padding-top: 20px">
                            <div class="flex_style"
                                style="border-top: 1px solid #f6f7f9" @click="logout">
                                <vab-icon icon="logout-circle-r-line" />
                                <span>退出登录</span>
                            </div>
                        </div>
                    </el-dropdown-menu>
                </template>
            </el-dropdown> -->
        </div>

    </div>
</template>
<script lang="ts" setup>
import {onMounted, ref} from 'vue'
import { toLoginRoute } from '@/utils/routes'
import { getUserInfo } from '@/api/user'
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/stores/modules/user'
const userStore = useUserStore()
import { useRouter } from 'vue-router' // 引用vue-router
const router = useRouter()
const { logout } = userStore

// const { avatar, username } = storeToRefs(userStore)


const username = ref('')
const active = ref('')

const goHome = ()=> {
    router.push('/home')
}


const logoutFn = async()=> {
    await logout()
    router.push('/index')

}

// 获取用户信息
const getUser = async () => {
  const { code, message, result } = await getUserInfo()
  if (code == 0) {
    username.value = result.username
    active.value = result.avatar
    userStore.setUserInfo(result)
    userStore.setAvatar(result.avatar)
  }
}
onMounted(()=> {
    getUser()
})
</script>

<style lang="scss" scoped>
.header-vue {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 57px;
    padding: 0 50px;
    box-sizing: border-box;
    line-height: normal;
    background: #fff;

    .header-img {
        width: 130px;

        img {
            width: 100%;
            cursor: pointer;
        }
    }
    .flex_style {
            display: flex;
            justify-content: center;
            cursor: pointer;
            margin-top: 20px;
            padding-top: 20px;
            padding-bottom: 10px
    }
}
</style>